define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'recovery/devoteset/index' + location.search,
                    add_url: 'recovery/devoteset/add',
                    edit_url: 'recovery/devoteset/edit',
                    del_url: 'recovery/devoteset/del',
                    multi_url: 'recovery/devoteset/multi',
                    import_url: 'recovery/devoteset/import',
                    table: 'recovery_devoteset',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), visible: false, operate: false},
                        // {field: 'recovery_category_id', title: __('Recovery_category_id'), visible: false},
                        // {field: 'recoverycategory.id', title: __('Recoverycategory.id'), operate: false},
                        // {field: 'recoverycategory.pid', title: __('Recoverycategory.pid'), operate: false},
                        // {field: 'recoverycategory.code', title: __('Recoverycategory.code'), operate: false},
                        {field: 'recoverycategory.name', title: __('Recoverycategory.name'), operate: 'LIKE'},
                        {field: 'describe', title: __('describe'), operate: false,
                            formatter: function(value){
                                return '<div style="max-width:450px; word-break: normal;white-space: normal; text-align: left;">'+value+'<div>';
                            }
                        },
                        {field: 'devoteparam', title: __('devoteparam'), operate: false,
                            formatter: function(value, row){
                                var str = '';
                                if(value[0].custom_one!='' && value[0].proportion!='' && value[0].custom_two!=''){
                                    str += value[0].custom_one+"【客户回收"+row.recoverycategory.name+"*"+value[0].proportion+"】"+value[0].custom_two+"；";
                                }
                                if(value[0].custom_one!='' && value[0].proportion!='' && value[0].custom_two!=''){
                                    str += value[1].custom_one+"【客户回收"+row.recoverycategory.name+"*"+value[1].proportion+"】"+value[1].custom_two;
                                }
                                // console.log(value);
                                return str;
                            }
                        },
                        // {field: 'recoverycategory.unit', title: __('Recoverycategory.unit'), operate: false},
                        // {field: 'recoverycategory.price', title: __('Recoverycategory.price'), operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});